package com.mjf.cjt.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mjf.cjt.domain.TFwarehouse;
import com.mjf.cjt.mapper.TFwarehouseMapper;
import com.mjf.cjt.service.AsyncTMService;
import com.mjf.cjt.service.TFwarehouseService;
import com.mjf.cjt.vo.WarehouseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * desc
 * </p>
 *
 * @author chenshoumeng
 * @date 2025/5/18 02:58
 */
@Service
public class TFwarehouseServiceImpl extends ServiceImpl<TFwarehouseMapper, TFwarehouse> implements TFwarehouseService {

    @Autowired
    private AsyncTMService asyncTMService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void asyncCW() {
        List<WarehouseVO> warehouseVOS = asyncTMService.asyncCW();
        if (CollectionUtil.isEmpty(warehouseVOS)) {
            return;
        }
        List<TFwarehouse> tfwarehouses = new ArrayList<>();
        for (WarehouseVO warehouseVO : warehouseVOS) {
            TFwarehouse tfwarehouse = new TFwarehouse();
            tfwarehouse.setWhid(warehouseVO.getCode());
            tfwarehouse.setWhcode(warehouseVO.getCode());
            tfwarehouse.setWhname(warehouseVO.getName());
            tfwarehouses.add(tfwarehouse);
        }
        saveOrUpdateBatch(tfwarehouses);
    }
}
